{include file="./public/header" title="编辑订单信息"/}

<link href="https://cdn.bootcss.com/bootstrap-validator/0.5.3/css/bootstrapValidator.min.css" rel="stylesheet">

<body class="hold-transition skin-blue fixed sidebar-mini">
<div class="wrapper">

    {include file="./public/navi"/}

    <!--页面主体-->
    <div class="content-wrapper">
        <section class="content-header">
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> 后台</a></li>
                <li class="active">订单信息</li>
                <li class="active">编辑</li>
            </ol>
        </section>
        <section class="content">
            <div class="box box-primary">
                <div class="box-header with-border">
                    <div class="box-title">编辑</div>
                    <div class="box-tools">
                        <button onclick="javascript:history.back(-1);" type="button"
                                class="btn btn-box-tool"><i class="fa fa-chevron-left"></i> 返回
                        </button>
                        <button onclick="javascript:location.reload();" type="button"
                                class="btn btn-box-tool"><i class="fa fa-refresh"></i> 刷新
                        </button>
                    </div>
                </div>
                <!-- /.panel-heading -->
                <div class="box-body">

                    <form id="form" class="form-horizontal">
                        <input class="hidden" name="id" id="id" value="{$data.id}"/>
                        <div class="form-group">
                            <label for="name" class="col-md-2 control-label">客户姓名</label>
                            <div class="col-md-4">
                                <input type="text" class="form-control" name="name" id="name" value="{$data.name}"
                                       required
                                       data-bv-notempty-message="客户姓名不能为空"/>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="tel" class="col-md-2 control-label">手机号码</label>
                            <div class="col-md-4">
                                <input type="number" class="form-control" name="tel" id="tel" value="{$data.tel}"
                                       required
                                       data-bv-notempty-message="手机号码不能为空"
                                       pattern="^(((13[0-9]{1})|(14[5|7]{1})|(15[0-35-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$"
                                       data-bv-regexp-message="手机号码格式有误"/>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="address" class="col-md-2 control-label">装修地址</label>
                            <div class="col-md-4">
                                <input type="text" class="form-control" name="address" id="address"
                                       value="{$data.address}"
                                       required
                                       data-bv-notempty-message="装修地址不能为空"/>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="oid" class="col-md-2 control-label">单号</label>
                            <div class="col-md-4">
                                <input type="number" class="form-control" name="oid" id="oid" value="{$data.oid}"
                                       required
                                       data-bv-notempty-message="单号不能为空"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="cid" class="col-md-2 control-label">卡号</label>
                            <div class="col-md-4">
                                <input type="number" class="form-control" name="cid" id="cid" value="{$data.cid}"
                                       required
                                       data-bv-notempty-message="卡号不能为空"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="price" class="col-md-2 control-label">订金金额</label>
                            <div class="col-md-4">
                                <input type="text" class="form-control" name="price" id="price"
                                       value="{$data.price}"
                                       required
                                       data-bv-notempty-message="订金金额不能为空"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="date" class="col-md-2 control-label">售卡日期</label>
                            <div class="col-md-4">
                                <input type="date" class="form-control" name="date" id="date" value="{$data.date}"
                                       required
                                       data-bv-notempty-message="售卡日期不能为空"/>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="brand" class="col-md-2 control-label">订购品牌</label>
                            <div class="col-md-4">
                                <select class="form-control" id="brand" name="brand" required
                                        data-bv-notempty-message="订购品牌不能为空">
                                    <option value="">请选择订购品牌</option>
                                    {volist name="brands" key="key" id="brand"}
                                    <option
                                            {if condition="$data['brand'] eq $brand" }
                                            selected="selected"
                                            {/if} value="{$brand}" >
                                    {$brand}
                                    </option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <hr>
                        <div class="form-group">
                            <div class="col-md-10 col-xs-offset-2">
                                <button id="save" type="button" class="btn btn-primary btn-flat">保存修改</button>
                            </div>
                        </div>
                    </form>
                </div>
                <!-- /.panel-body -->
            </div>
            <!-- /.panel -->
        </section>
    </div>
    <!-- /#page-wrapper -->

</div>
<!-- /#wrapper -->

{include file="public/js"/}
<script src="https://cdn.bootcss.com/bootstrap-validator/0.5.3/js/bootstrapValidator.min.js"></script>

<script>
    var form = $('#form');
    $(function () {
        $('form').bootstrapValidator({
            message: '验证失败',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            }
        });
    });

    $("#save").click(function () {
        //进行表单验证
        var bv = form.data('bootstrapValidator');
        bv.validate();
        if (bv.isValid()) {
            var data = new FormData(document.getElementById("form"));
            $.ajax({
                url: "{:url('admin/order/edit')}",
                type: "POST",
                data: data,
                processData: false, // 告诉jQuery不要去处理发送的数据
                contentType: false, // 告诉jQuery不要去设置Content-Type请求头
                success: function (data) {
                    if (data.code === 0) {
                        layer.msg(data.msg, {icon: 5})
                    } else {
                        layer.msg('修改成功！', {icon: 6});
                        bv.resetForm();
                        document.getElementById("form").reset();
                    }
                },
                error: function () {
                    alert("连接失败");
                }
            });
        }
    });
</script>
</body>

</html>